#include "header/pyramid_coffin.h"

OSG_USING_NAMESPACE
using std::cout;
using std::endl;


//function wich implements the coffin in our scengraph
NodePtr createCoffin(){
	Matrix m;
	
	/*
	 * Start Coffin definition
	 */
	GeoPTypesPtr coffinType = GeoPTypesUI8::create();        
	beginEditCP (coffinType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		coffinType->addValue(GL_QUADS);

	}
	endEditCP (coffinType, GeoPTypesUI8::GeoPropDataFieldMask);
		
	GeoPLengthsPtr coffinLens = GeoPLengthsUI32::create();    
	beginEditCP (coffinLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		coffinLens->addValue(58);
	}
	endEditCP (coffinLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	//End coffin defnition
	
	/*
	 * Start Coffin cover definition
	 */
	GeoPTypesPtr coffinCoverType = GeoPTypesUI8::create();        
	beginEditCP (coffinCoverType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		coffinCoverType->addValue(GL_QUADS);

	}
	endEditCP (coffinCoverType, GeoPTypesUI8::GeoPropDataFieldMask);
		
	GeoPLengthsPtr coffinCoverLens = GeoPLengthsUI32::create();    
	beginEditCP (coffinCoverLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		coffinCoverLens->addValue(8);

	}
	endEditCP (coffinCoverLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	// End Coffin cover definition

	/*
	 * Start Coffin cover sides definition
	 */
	GeoPTypesPtr coffinCoverSidesType = GeoPTypesUI8::create();        
	beginEditCP (coffinCoverSidesType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		coffinCoverSidesType->addValue(GL_QUADS);

	}
	endEditCP (coffinCoverSidesType, GeoPTypesUI8::GeoPropDataFieldMask);
		
	GeoPLengthsPtr coffinCoverSidesLens = GeoPLengthsUI32::create();    
	beginEditCP (coffinCoverSidesLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		coffinCoverSidesLens->addValue(16);

	}
	endEditCP (coffinCoverSidesLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	//End Coffin cover sides definition
	
	
	
	GeoPositions3fPtr coffinPnts = GeoPositions3f::create();
		beginEditCP (coffinPnts, GeoPositions3f::GeoPropDataFieldMask);
		{

			//########Cords wall frontside#######			

			coffinPnts->addValue(Pnt3f(0, 10, 0));
			coffinPnts->addValue(Pnt3f(0, 30, 0));
			coffinPnts->addValue(Pnt3f(100, 30, 0));
			coffinPnts->addValue(Pnt3f(100, 10, 0));
			
			
			//Punkte rückseite 4 5 6 7
			coffinPnts->addValue(Pnt3f(2, 10, -2));
			coffinPnts->addValue(Pnt3f(2, 30, -2));
			coffinPnts->addValue(Pnt3f(98, 30, -2));
			coffinPnts->addValue(Pnt3f(98, 10, -2));
						
			//########End cords wall frontside##########
			
			//########Cords wall backside##################

			coffinPnts->addValue(Pnt3f(0, 10, -40));
			coffinPnts->addValue(Pnt3f(0, 30, -40));
			coffinPnts->addValue(Pnt3f(100, 30, -40));
			coffinPnts->addValue(Pnt3f(100, 10, -40));

			
			coffinPnts->addValue(Pnt3f(2, 10, -38));
			coffinPnts->addValue(Pnt3f(2, 30, -38));
			coffinPnts->addValue(Pnt3f(98, 30, -38));
			coffinPnts->addValue(Pnt3f(98, 10, -38));
						
			//#####End points wall backside	
			
			//########Cords right wall##################			

			coffinPnts->addValue(Pnt3f(100, 10, 0));
			coffinPnts->addValue(Pnt3f(100, 30, 0));
			coffinPnts->addValue(Pnt3f(100, 30, -40));
			coffinPnts->addValue(Pnt3f(100, 10, -40));

			coffinPnts->addValue(Pnt3f(98, 10, -2));
			coffinPnts->addValue(Pnt3f(98, 30, -2));
			coffinPnts->addValue(Pnt3f(98, 30, -38));
			coffinPnts->addValue(Pnt3f(98, 10, -38));
						
			//#####End cords right wall				
			
			//########Cords left wall##################			
				
			//vorne 0 1 9 8
			coffinPnts->addValue(Pnt3f(0, 10, 0));
			coffinPnts->addValue(Pnt3f(0, 30, 0));
			coffinPnts->addValue(Pnt3f(0, 30, -40));
			coffinPnts->addValue(Pnt3f(0, 10, -40));
						
			//hinten 4 5 13 12
			coffinPnts->addValue(Pnt3f(2, 10, -2));
			coffinPnts->addValue(Pnt3f(2, 30, -2));
			coffinPnts->addValue(Pnt3f(2, 30, -38));
			coffinPnts->addValue(Pnt3f(2, 10, -38));
						
			//#####End cords left wall	
			}
		endEditCP (coffinPnts, GeoPositions3f::GeoPropDataFieldMask);	

		
	/*********************
	 * Coffin cover Pnts
	 * ********************/
		
	GeoPositions3fPtr coffinCoverPnts = GeoPositions3f::create();
		beginEditCP (coffinCoverPnts, GeoPositions3f::GeoPropDataFieldMask);
		{

		//Cover top cords
		coffinCoverPnts->addValue(Pnt3f(-4, 30, 4));
		coffinCoverPnts->addValue(Pnt3f(-4, 30, -44));
		coffinCoverPnts->addValue(Pnt3f(104, 30, -44));
		coffinCoverPnts->addValue(Pnt3f(104, 30, 4));
					
		//Cover bottom cordds
		coffinCoverPnts->addValue(Pnt3f(-4, 34, 4));
		coffinCoverPnts->addValue(Pnt3f(-4, 34, -44));
		coffinCoverPnts->addValue(Pnt3f(104, 34, -44));
		coffinCoverPnts->addValue(Pnt3f(104, 34, 4));
		}
		endEditCP (coffinCoverPnts, GeoPositions3f::GeoPropDataFieldMask);
		
	/*********************
	 * Coffin coverSides Pnts
	* ********************/			
				
	GeoPositions3fPtr coffinCoverSidesPnts = GeoPositions3f::create();
		beginEditCP (coffinCoverSidesPnts, GeoPositions3f::GeoPropDataFieldMask);
		{


			//front side cords
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 30, 4));
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 34, 4));
			coffinCoverSidesPnts->addValue(Pnt3f(104, 34, 4));
			coffinCoverSidesPnts->addValue(Pnt3f(104, 30, 4));
							
			//back side cords
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 30, -44));
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 34, -44));
			coffinCoverSidesPnts->addValue(Pnt3f(104, 34, -44));
			coffinCoverSidesPnts->addValue(Pnt3f(104, 30, -44));
							
			//right side cords
			coffinCoverSidesPnts->addValue(Pnt3f(104, 30, 4));
			coffinCoverSidesPnts->addValue(Pnt3f(104, 34, 4));
			coffinCoverSidesPnts->addValue(Pnt3f(104, 34, -44));
			coffinCoverSidesPnts->addValue(Pnt3f(104, 30, -44));
							
			//left side cords
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 30, 4));
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 34, 4));
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 34, -44));
			coffinCoverSidesPnts->addValue(Pnt3f(-4, 30, -44));


		
		}	
	endEditCP (coffinCoverSidesPnts, GeoPositions3f::GeoPropDataFieldMask);
	
	
	//texture cords for our coffin, the cords are defined  against clock sense
	//The Vector shows to the next defines Point.
	GeoTexCoords2fPtr coffinTex = GeoTexCoords2f::create();
		beginEditCP (coffinTex);{
	
			//front
			coffinTex->addValue(Vec2f(1,0));
			coffinTex->addValue(Vec2f(1,1));		
			coffinTex->addValue(Vec2f(0,1));
			coffinTex->addValue(Vec2f(0,0));
	
			coffinTex->addValue(Vec2f(1,0));
			coffinTex->addValue(Vec2f(1,1));		
			coffinTex->addValue(Vec2f(0,1));
			coffinTex->addValue(Vec2f(0,0));	
					
			//back
			coffinTex->addValue(Vec2f(0,0));
			coffinTex->addValue(Vec2f(0,1));
			coffinTex->addValue(Vec2f(1,1));
			coffinTex->addValue(Vec2f(1,0));
			
			coffinTex->addValue(Vec2f(0,0));
			coffinTex->addValue(Vec2f(0,1));		
			coffinTex->addValue(Vec2f(1,1));
			coffinTex->addValue(Vec2f(1,0));
			
			//right
			coffinTex->addValue(Vec2f(1,0));
			coffinTex->addValue(Vec2f(1,1));		
			coffinTex->addValue(Vec2f(0,1));
			coffinTex->addValue(Vec2f(0,0));
	
			coffinTex->addValue(Vec2f(1,0));
			coffinTex->addValue(Vec2f(1,1));		
			coffinTex->addValue(Vec2f(0,1));
			coffinTex->addValue(Vec2f(0,0));	
					
			//left
			coffinTex->addValue(Vec2f(0,0));
			coffinTex->addValue(Vec2f(0,1));
			coffinTex->addValue(Vec2f(1,1));
			coffinTex->addValue(Vec2f(1,0));
			
			coffinTex->addValue(Vec2f(0,0));
			coffinTex->addValue(Vec2f(0,1));		
			coffinTex->addValue(Vec2f(1,1));
			coffinTex->addValue(Vec2f(1,0));

		}
		endEditCP (coffinTex);
		
	//Texture cords coffinCover same like coffinTex
	GeoTexCoords2fPtr coffinCoverTex = GeoTexCoords2f::create();
		beginEditCP (coffinCoverTex);{

			//front
			coffinCoverTex->addValue(Vec2f(1,0));
			coffinCoverTex->addValue(Vec2f(1,1));		
			coffinCoverTex->addValue(Vec2f(0,1));
			coffinCoverTex->addValue(Vec2f(0,0));

			//back
			coffinCoverTex->addValue(Vec2f(1,0));
			coffinCoverTex->addValue(Vec2f(1,1));		
			coffinCoverTex->addValue(Vec2f(0,1));

		}
		endEditCP (coffinCoverTex);		
				
		
	//Textur cords coffinCoverSides
	GeoTexCoords2fPtr coffinCoverSidesTex = GeoTexCoords2f::create();
		beginEditCP (coffinCoverSidesTex);{

			//front
			coffinCoverSidesTex->addValue(Vec2f(1,0));
			coffinCoverSidesTex->addValue(Vec2f(1,1));
			coffinCoverSidesTex->addValue(Vec2f(0,1));
			coffinCoverSidesTex->addValue(Vec2f(0,0));

			//back
			coffinCoverSidesTex->addValue(Vec2f(1,0));
			coffinCoverSidesTex->addValue(Vec2f(1,1));		
			coffinCoverSidesTex->addValue(Vec2f(0,1));
			coffinCoverSidesTex->addValue(Vec2f(0,0));	
				
			//right
			coffinCoverSidesTex->addValue(Vec2f(0,0));
			coffinCoverSidesTex->addValue(Vec2f(0,1));
			coffinCoverSidesTex->addValue(Vec2f(1,1));
			coffinCoverSidesTex->addValue(Vec2f(1,0));
		
			//left
			coffinCoverSidesTex->addValue(Vec2f(0,0));
			coffinCoverSidesTex->addValue(Vec2f(0,1));		
			coffinCoverSidesTex->addValue(Vec2f(1,1));
			coffinCoverSidesTex->addValue(Vec2f(1,0));

		}
		endEditCP (coffinCoverSidesTex);

		

	/***********************
	 * Put all Points from the coffin together
	 * *************************/
	GeoIndicesUI32Ptr coffinIndices = GeoIndicesUI32::create();
		beginEditCP (coffinIndices, GeoIndicesUI32::GeoPropDataFieldMask);
		{
			
			//############front wall			
			//front
			coffinIndices->addValue(0);
			coffinIndices->addValue(1);
			coffinIndices->addValue(2);
			coffinIndices->addValue(3);
			
			//back
			coffinIndices->addValue(4);
			coffinIndices->addValue(5);
			coffinIndices->addValue(6);
			coffinIndices->addValue(7);
			
			//###########End front wall
			
			//###########back wall
			//front
			coffinIndices->addValue(8);
			coffinIndices->addValue(9);
			coffinIndices->addValue(10);
			coffinIndices->addValue(11);
			
			//back
			coffinIndices->addValue(12);
			coffinIndices->addValue(13);
			coffinIndices->addValue(14);
			coffinIndices->addValue(15);	
			
			//###########End back wall
			
			//right wall			
			//front
			coffinIndices->addValue(16);
			coffinIndices->addValue(17);
			coffinIndices->addValue(18);
			coffinIndices->addValue(19);
			
			//back
			coffinIndices->addValue(20);
			coffinIndices->addValue(21);
			coffinIndices->addValue(22);
			coffinIndices->addValue(23);		
			//End right wall
			
			//left wall		
			//front
			coffinIndices->addValue(24);
			coffinIndices->addValue(25);
			coffinIndices->addValue(26);
			coffinIndices->addValue(27);
			
			//back
			coffinIndices->addValue(28);
			coffinIndices->addValue(29);
			coffinIndices->addValue(30);
			coffinIndices->addValue(31);	
			//End left wall
			
			
			//#######over alliance
			// right
			coffinIndices->addValue(2);
			coffinIndices->addValue(10);
			coffinIndices->addValue(14);
			coffinIndices->addValue(6);

			
			//left
			coffinIndices->addValue(1);
			coffinIndices->addValue(9);
			coffinIndices->addValue(13);
			coffinIndices->addValue(5);
			
			//front
			coffinIndices->addValue(1);
			coffinIndices->addValue(5);
			coffinIndices->addValue(6);
			coffinIndices->addValue(2);	
			
			//back
			coffinIndices->addValue(9);
			coffinIndices->addValue(10);
			coffinIndices->addValue(14);
			coffinIndices->addValue(13);

			//#######over alliance end			

		}
		endEditCP (coffinIndices, GeoIndicesUI32::GeoPropDataFieldMask);
		
	/***********************
	 * Put all PointsCover from the coffin together
	* *************************/
	GeoIndicesUI32Ptr coffinCoverIndices = GeoIndicesUI32::create();
		beginEditCP (coffinCoverIndices, GeoIndicesUI32::GeoPropDataFieldMask);
		{
					
			
			//top
			coffinCoverIndices->addValue(0);
			coffinCoverIndices->addValue(1);
			coffinCoverIndices->addValue(2);
			coffinCoverIndices->addValue(3);
					
			//bottom
			coffinCoverIndices->addValue(4);
			coffinCoverIndices->addValue(5);
			coffinCoverIndices->addValue(6);
			coffinCoverIndices->addValue(7);

					
		}
		endEditCP (coffinCoverIndices, GeoIndicesUI32::GeoPropDataFieldMask);
		
	/***********************
	* Put all PointsCoverSides from the coffin together
	* *************************/
	GeoIndicesUI32Ptr coffinCoverSidesIndices = GeoIndicesUI32::create();
			beginEditCP (coffinCoverSidesIndices, GeoIndicesUI32::GeoPropDataFieldMask);
			{

				//front
				coffinCoverSidesIndices->addValue(0);
				coffinCoverSidesIndices->addValue(1);
				coffinCoverSidesIndices->addValue(2);
				coffinCoverSidesIndices->addValue(3);

					
				//back
				coffinCoverSidesIndices->addValue(4);
				coffinCoverSidesIndices->addValue(5);
				coffinCoverSidesIndices->addValue(6);
				coffinCoverSidesIndices->addValue(7);
				
				//right
				coffinCoverSidesIndices->addValue(8);
				coffinCoverSidesIndices->addValue(9);
				coffinCoverSidesIndices->addValue(10);
				coffinCoverSidesIndices->addValue(11);
					
				//left
				coffinCoverSidesIndices->addValue(12);
				coffinCoverSidesIndices->addValue(13);
				coffinCoverSidesIndices->addValue(14);
				coffinCoverSidesIndices->addValue(15);
					
					
			}
			endEditCP (coffinCoverSidesIndices, GeoIndicesUI32::GeoPropDataFieldMask);
			
			/**********************
			 * Normals
			 * *******************/			
		    GeoNormals3fPtr coffinNorms = GeoNormals3f::create();
		    beginEditCP(coffinNorms, GeoNormals3f::GeoPropDataFieldMask);
		    
		    	int x;
		    	//front
		        for (x=0; x < 4; x++)
		                coffinNorms->addValue(Vec3f(0,0,1));
		        
		        for (x=4; x < 8; x++)
			            coffinNorms->addValue(Vec3f(0,0,-1));
		        
		        //back
		        for (x=8; x < 12; x++)
		                coffinNorms->addValue(Vec3f(0,0,-1));
		        
		        for (x=12; x < 16; x++)
		                coffinNorms->addValue(Vec3f(0,0,1));
		        
		        //right
		        for (x=16; x < 20; x++)
			            coffinNorms->addValue(Vec3f(1,0,0));
		        
		        for (x=20; x < 24; x++)
			            coffinNorms->addValue(Vec3f(-1,0,0));
		        
		        //left
		        for (x=24; x < 28; x++)
			            coffinNorms->addValue(Vec3f(-1,0,0));
		        
		        for (x=28; x < 32; x++)
			            coffinNorms->addValue(Vec3f(1,0,0));

		        
		    endEditCP(coffinNorms, GeoNormals3f::GeoPropDataFieldMask);
			
		    GeoNormals3fPtr coffinCoverNorms = GeoNormals3f::create();
		    	beginEditCP(coffinCoverNorms, GeoNormals3f::GeoPropDataFieldMask);
			        for (int x = 0; x < 4; x++)
			        	coffinCoverNorms->addValue(Vec3f(0,-1,0));
			        for (int x = 4; x < 8; x++)
			        	coffinCoverNorms->addValue(Vec3f(0,1,0));

		        endEditCP(coffinCoverNorms, GeoNormals3f::GeoPropDataFieldMask);
		    
		    GeoNormals3fPtr coffinCoverSidesNorms = GeoNormals3f::create();
		    	beginEditCP(coffinCoverSidesNorms, GeoNormals3f::GeoPropDataFieldMask);
		  		    
		  		    int y;
		  		    for (y=0; y < 4; y++)
		  		        coffinCoverSidesNorms->addValue(Vec3f(0,0,1));
		  		    	
		  		    for (y=4; y < 8; y++)
		  		        coffinCoverSidesNorms->addValue(Vec3f(0,0,-1));
		  		        
		  		    for (y=8; y < 12; y++)
		  		        coffinCoverSidesNorms->addValue(Vec3f(1,0,0));
		  		        
		  		    for (y=12; y < 16; y++)
		  		        coffinCoverSidesNorms->addValue(Vec3f(-1,0,0));

		  		        
		  		 endEditCP(coffinCoverSidesNorms, GeoNormals3f::GeoPropDataFieldMask);


				
		/*************************************+
		 * Set material for the coffin in marmor look
		 * ******************************************/
		  		    
		//load image
		ImagePtr marmorImage = Image::create();
		marmorImage->read("materials/marmor.jpg");		
		
		//Set material options
		SimpleTexturedMaterialPtr marmorMaterial = SimpleTexturedMaterial::create();		    
		    beginEditCP(marmorMaterial);
		    {
		    	marmorMaterial->setAmbient      (Color3f(0.3, 0.3, 0.3));
		    	marmorMaterial->setDiffuse      (Color3f(1.0, 1.0, 1.0));
		    	marmorMaterial->setSpecular		(Color3f(0.6, 0.6, 0.6));
		    	marmorMaterial->setShininess    (60);
			    
		    	marmorMaterial->setEnvMode(GL_MODULATE);
			        
		    	marmorMaterial->setImage        (marmorImage);
		    	marmorMaterial->setMinFilter    (GL_LINEAR_MIPMAP_LINEAR);
		    	marmorMaterial->setMagFilter    (GL_LINEAR);			
		        
		    }
		    endEditCP  (marmorMaterial);
		    
		/*********************
		* Set material for the coffin in gold look
		***************************/		    
			
		//Load gold image
		ImagePtr goldImage = Image::create();
		goldImage->read("materials/gold.jpg");		

		//Set material options
		SimpleTexturedMaterialPtr goldMaterial = SimpleTexturedMaterial::create();		    
		    beginEditCP(goldMaterial);
		    {
		        goldMaterial->setAmbient      (Color3f(0.3, 0.3, 0.3));
			    goldMaterial->setDiffuse      (Color3f(1.0, 1.0, 1.0));
		    	goldMaterial->setSpecular	  (Color3f(1.0, 1.0, 1.0));
			    goldMaterial->setShininess    (100);
			    
			    goldMaterial->setEnvMode(GL_MODULATE);
			        
			    goldMaterial->setImage        (goldImage);
			    goldMaterial->setMinFilter    (GL_LINEAR_MIPMAP_LINEAR);
			    goldMaterial->setMagFilter    (GL_LINEAR);			        
			 }
			 endEditCP  (goldMaterial);


		// Put all options together in a GeometryPointer for coffin
		GeometryPtr coffinGeo = Geometry::create();
			beginEditCP (coffinGeo, Geometry::TypesFieldMask    |
				Geometry::LengthsFieldMask   |
				Geometry::IndicesFieldMask   |
				Geometry::PositionsFieldMask |
				Geometry::MaterialFieldMask  );
		{
			coffinGeo->setTypes    (coffinType);
			coffinGeo->setLengths  (coffinLens);
			coffinGeo->setIndices  (coffinIndices);
			coffinGeo->setTexCoords(coffinTex);
			coffinGeo->setPositions(coffinPnts);
			coffinGeo->setMaterial(marmorMaterial);
			coffinGeo->setNormals(coffinNorms);
	
		}
			endEditCP (coffinGeo, Geometry::TypesFieldMask    |
				Geometry::LengthsFieldMask   |
				Geometry::IndicesFieldMask   |
				Geometry::PositionsFieldMask |
				Geometry::MaterialFieldMask  );	
		
		
		// Put all options together in a GeometryPointer for coffinCover
		GeometryPtr coffinCoverGeo=Geometry::create();
			beginEditCP (coffinCoverGeo, Geometry::TypesFieldMask    |
				Geometry::LengthsFieldMask   |
				Geometry::IndicesFieldMask   |
				Geometry::PositionsFieldMask |
				Geometry::MaterialFieldMask  );
		{
			coffinCoverGeo->setTypes    (coffinCoverType);
			coffinCoverGeo->setLengths  (coffinCoverLens);
			coffinCoverGeo->setIndices  (coffinCoverIndices);
			coffinCoverGeo->setTexCoords(coffinCoverTex);
			coffinCoverGeo->setPositions(coffinCoverPnts);
			coffinCoverGeo->setMaterial(goldMaterial);   
			coffinCoverGeo->setNormals(coffinCoverNorms);


		}
			endEditCP (coffinCoverGeo, Geometry::TypesFieldMask    |
				Geometry::LengthsFieldMask   |
				Geometry::IndicesFieldMask   |
				Geometry::PositionsFieldMask |
				Geometry::MaterialFieldMask  );	
		
		
		// Put all options together in a GeometryPointer for coffinCoverSides
		GeometryPtr coffinCoverSidesGeo=Geometry::create();
			beginEditCP (coffinCoverSidesGeo, Geometry::TypesFieldMask    |
					Geometry::LengthsFieldMask   |
					Geometry::IndicesFieldMask   |
					Geometry::PositionsFieldMask |
					Geometry::MaterialFieldMask  );
			{
				coffinCoverSidesGeo->setTypes    (coffinCoverSidesType);
				coffinCoverSidesGeo->setLengths  (coffinCoverSidesLens);
				coffinCoverSidesGeo->setIndices  (coffinCoverSidesIndices);
				coffinCoverSidesGeo->setTexCoords(coffinCoverSidesTex);
				coffinCoverSidesGeo->setPositions(coffinCoverSidesPnts);
				coffinCoverSidesGeo->setMaterial(goldMaterial);
				coffinCoverSidesGeo->setNormals(coffinCoverSidesNorms);
			}
			endEditCP (coffinCoverSidesGeo, Geometry::TypesFieldMask    |
					Geometry::LengthsFieldMask   |
					Geometry::IndicesFieldMask   |
					Geometry::PositionsFieldMask |
					Geometry::MaterialFieldMask  );	
			
			
		//coffinCover Node Pointer
		NodePtr coffinCover = Node::create();
			beginEditCP(coffinCover, Node::CoreFieldMask);{
				coffinCover->setCore(coffinCoverGeo);
				}
			endEditCP  (coffinCover, Node::CoreFieldMask);

		//coffinCover Pointer
		NodePtr coffinCoverSides = Node::create();
			beginEditCP(coffinCoverSides, Node::CoreFieldMask);{
				coffinCoverSides->setCore(coffinCoverSidesGeo);
				}
			endEditCP  (coffinCoverSides, Node::CoreFieldMask);
				
		
		//coffin Pointer
		NodePtr coffin = Node::create();
			beginEditCP(coffin, Node::CoreFieldMask);{
				coffin->setCore(coffinGeo);		}
			endEditCP  (coffin, Node::CoreFieldMask);
		
		NodePtr coffinPodium = makeBox(200, 10, 60, 10, 10, 10);
			
		TransformPtr tcoffinPodium = Transform::create();
			beginEditCP(tcoffinPodium, Transform::MatrixFieldMask);
				m.setIdentity();
				m.setTranslate(50, 5, -20);
				tcoffinPodium->setMatrix(m);
			endEditCP(tcoffinPodium, Transform::MatrixFieldMask);
			
		NodePtr coffinPodiumTrans = Node::create();
			beginEditCP(coffinPodiumTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
				coffinPodiumTrans->setCore(tcoffinPodium);
				coffinPodiumTrans->addChild(coffinPodium);
			endEditCP(coffinPodiumTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);

		     
		 ImagePtr coffinPodiumImage = Image::create();
		 coffinPodiumImage->read("materials/marmor2.jpg");
		     		
		 TextureChunkPtr coffinPodiumTex = TextureChunk::create();
			 beginEditCP(coffinPodiumTex);
			     coffinPodiumTex->setImage(coffinPodiumImage);
			     coffinPodiumTex->setMinFilter(GL_LINEAR);
			     coffinPodiumTex->setMagFilter(GL_LINEAR);
			     coffinPodiumTex->setWrapS(GL_REPEAT);
			     coffinPodiumTex->setWrapT(GL_REPEAT);
			     coffinPodiumTex->setEnvMode(GL_MODULATE);
		     endEditCP(coffinPodiumTex);
		     	
		  SimpleMaterialPtr coffinPodiumMat = SimpleMaterial::create();
		     beginEditCP(coffinPodiumMat);
			     coffinPodiumMat->setAmbient(Color3f(0.3, 0.3, 0.3)); 
			     coffinPodiumMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
			     coffinPodiumMat->setSpecular(Color3f(0.5, 0.5, 0.5));
			     coffinPodiumMat->addChunk(coffinPodiumTex);
		     endEditCP(coffinPodiumMat);
		     		
	    GeometryPtr coffinPodiumGeo = GeometryPtr::dcast(coffinPodium->getCore());
		    beginEditCP(coffinPodiumGeo);
		     	coffinPodiumGeo->setMaterial(coffinPodiumMat);
		    endEditCP(coffinPodiumGeo);

		// Take all Pointers together as one the represents the hole coffin
		NodePtr wholeCoffin = Node::create();
			beginEditCP(wholeCoffin, Node::CoreFieldMask);
			{
			wholeCoffin->setCore(Group::create());
			wholeCoffin->addChild(coffin);
			wholeCoffin->addChild(coffinCover);
			wholeCoffin->addChild(coffinCoverSides);
			wholeCoffin->addChild(coffinPodiumTrans);
			}
		endEditCP  (wholeCoffin, Node::CoreFieldMask);

		/*NodePtr r1_norm = calcVertexNormalsGeo(coffinGeo, 5.0);
		SimpleMaterialPtr mat = SimpleMaterial::create();
				
		GeometryPtr geo = GeometryPtr::dcast(r1_norm->getCore());
		beginEditCP(geo);
			geo->setMaterial(mat);
		endEditCP(geo);
				
		NodePtr rotaryBody = Node::create();
		beginEditCP(rotaryBody);
			rotaryBody->setCore(Group::create());
			rotaryBody->addChild(r1_norm);
			rotaryBody->addChild(holeCoffin);
		endEditCP(rotaryBody);
		return rotaryBody;*/
		
		return wholeCoffin;
}
